import { createSlice } from "@reduxjs/toolkit";

export const personListSlice = createSlice({
  name: "personList",
  initialState: {
    personList: [
      {
        id: "1",
        name: "张三",
        code: "1234567654321234565",
      },
      {
        id: "2",
        name: "李四",
        code: "123234543234565432",
      },
    ],
  },
  reducers: {
    delPerson(state, action) {
      state.personList = state.personList.filter(
        (v) => v.id !== action.payload.id
      );
    },
    addPerson(state, action) {
      state.personList.push({
        ...action.payload,
        id: new Date().getTime(),
      });
    },
  },
});

export const { delPerson, addPerson } = personListSlice.actions;
